namespace Cil.Ast;

public sealed class ConditionExpression : Expression
{
	public const int ConditionPos = 0;
	public const int EvaluationPos = 1;
	public const int MaxNodes = 2;

	public ConditionExpression(Context context, Expression condition) 
		: this(context, condition, new Expression(context))
	{
	}

	public ConditionExpression(Context context, Expression condition, Expression evaluation) : base(context)
	{
		ReadsStack = 1;
		WritesStack = 0;

		Nodes = new FixedList<Expression>(MaxNodes);

		Condition = condition;
		Evaluation = evaluation;
	}
		
	public Expression Condition { get { return Nodes[ConditionPos]; } set { Nodes[ConditionPos] = value; value.ParentNode = this; } }
		
	public Expression Evaluation { get { return Nodes[EvaluationPos]; } set { Nodes[EvaluationPos] = value; value.ParentNode = this; } }

	public override string ToString()
	{
		if (Evaluation.IsEmpty)
		{
			return Condition.ToString();
		}
		else
		{
			return string.Format("[[{1}]]\r\n{0}", Condition, Evaluation);
		}
	}
}